﻿Imports System.Data.SqlClient
Public Class frmUsuariosListado
    Private mstrCondicion As String
    Private mstrValor As String
    Dim mdsDatos As New DataSet
    Public WriteOnly Property Condicion() As String
        Set(ByVal value As String)
            mstrCondicion = value
        End Set
    End Property
    Public ReadOnly Property Valor() As String
        Get
            Valor = mstrValor
        End Get
    End Property
    Private Sub frmUsuariosListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Actualizar()
    End Sub

    Private Sub RadButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton2.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
    Sub Actualizar()
        Windows.Forms.Cursor.Current = Cursors.WaitCursor
        dgUsuarios.Rows.Clear()

        Dim cnconn As New SqlConnection
        cnconn.ConnectionString = InitialConnection
        Dim strSql As String = ""
        cnconn.Open()
        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnconn

        strSql = "SELECT * FROM Usuarios WHERE IdUsuario>1"


        cmdBuscar.CommandText = strSql
        Dim rdBuscar As SqlDataReader
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            dgUsuarios.Rows.Add(rdBuscar("IdUsuario"), rdBuscar("Nombre").ToString.Trim, rdBuscar("NombreCompleto").ToString.Trim)
        Loop
    End Sub

    Private Sub btnAbrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbrir.Click
        Dim strRetVal As String = ""

        Try
            strRetVal = CStr(dgUsuarios.Item(1, dgUsuarios.CurrentCell.RowIndex).Value)
        Catch ex As Exception
            strRetVal = ""
        Finally
            mstrValor = strRetVal.Trim
        End Try

        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub
    Private Sub dgResult_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgUsuarios.CellDoubleClick

        btnAbrir_Click(Me, System.EventArgs.Empty)

    End Sub

    Private Sub dgResult_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgUsuarios.KeyDown

        If e.KeyCode = Keys.Enter Then
            btnAbrir_Click(Me, System.EventArgs.Empty)
        End If

    End Sub
End Class